package com.suxin.netty.protocol;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author Tang
 * @classname MySimpleEncoder
 * @description [ TODO ]
 * @date 2021/1/11 21:16
 */
public class MySimpleEncoder extends MessageToByteEncoder<ProtocolMessage> {

    @Override
    protected void encode(ChannelHandlerContext ctx, ProtocolMessage msg, ByteBuf out) throws Exception {
        System.out.println("MySimpleEncoder...编码写入...");
        out.writeInt(msg.getLen());
        out.writeBytes(msg.getMsg());
    }

}